package week07

import "bytes"

// 125. 验证回文串
// https://leetcode-cn.com/problems/valid-palindrome/

func isPalindrome(s string) bool {
	s1 := filter(s)
	var left, right = 0, len(s1)-1
	for left < right {
		if s1[left] != s1[right] {
			return false
		}
		left++
		right--
	}
	return true
}

func filter(str string) string {
	buf := &bytes.Buffer{}
	for i := range str {
		if str[i] >= 'a' && str[i] <= 'z' {
			buf.WriteByte(str[i])
		} else if str[i] >= 'A' && str[i] <= 'Z' {
			buf.WriteByte(str[i]+32)
		} else if str[i] >= '0' && str[i] <= '9' {
			buf.WriteByte(str[i])
		}
	}
	return buf.String()
}